<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "XHTML1-s.dtd" >
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		
<style>
.calendar_box *
{
	font-family:calibri;
}
.calendar_box
{
	border:1px solid #f5f5f5;
	position:absolute;
	width:200px;
	height:200px;
	background:#FFFFFF;
}
.calendar_head
{
	background:#f5f5f5;
	position:absolute;
	top:0px;
	left:0px;
	right:0px;
	height:30px;
}
.calendar_body
{
	background:#FFFFFF;
	position:absolute;
	top:30px;
	left:0px;
	right:0px;
	bottom:21px;
	overflow:hidden;
}
.calendar_foot
{
	background:#FFFFFF;
	border-top:1px solid #f5f5f5;
	position:absolute;
	height:20px;
	left:0px;
	right:0px;
	bottom:0px;
	text-align:center;
	cursor:pointer;
	color:#0066cc;
}
TABLE.calendar_mode
{
	top:0px;
	left:0px;
	right:0px;
	bottom:0px;
	width:100%;
	height:149px;
}
TABLE.calendar_mode TR.calendar_mode_0_head TD
{
	border-bottom:1px solid #f5f5f5;
	text-align:center;
	padding:0px;
}
TABLE.calendar_mode TR.calendar_mode_0_head TD:hover
{
	border:0px;
	border-bottom:1px solid #f5f5f5;
	background-color:transparent;
}
TABLE.calendar_mode TD
{
	cursor:pointer;
	padding:1px;
}
TABLE.calendar_mode TD:hover
{
	border:1px solid #cccccc;
	padding:0px;
	background-color:#fcfcfc;
}
TABLE.calendar_mode TD[selected]
{
	border:1px solid #0066cc;
	padding:0px;
	background-color:#ebf7fe;
}


TABLE.calendar_mode_0 TD
{
	text-align:right;
	padding-right:6px;
}
TABLE.calendar_mode_0 TD:hover
, TABLE.calendar_mode_0 TD[selected]
{
	padding-right:5px;
}

TABLE.calendar_mode_1 TD
, TABLE.calendar_mode_2 TD
, TABLE.calendar_mode_3 TD
{
	text-align:center;
}

TABLE.calendar_mode_0 TD
{
	width:14%;
}
TABLE.calendar_mode_1 TD
{
	width:25%;
}
TABLE.calendar_mode_2 TD
, TABLE.calendar_mode_3 TD
{
	width:50%;
}
TABLE.calendar_mode TD.calendar_out
{
	color:#e5e5e5;
}
TABLE.calendar_mode TD.calendar_in
{
	color:#000000;
}
.calendar_arrow_left
{
	position:absolute;
	top:6px;
	left:0px;
	height:16px;
	width:16px;
	background-image:url('./arrow_left.png');
	background-repeat:no-repeat;
	background-position:6px 4px;
	cursor:pointer;
}
.calendar_arrow_right
{
	position:absolute;
	top:6px;
	right:0px;
	height:16px;
	width:16px;
	background-image:url('./arrow_right.png');
	background-repeat:no-repeat;
	background-position:6px 4px;
	cursor:pointer;
}
.calendar_arrow_left:hover
{
	border:1px solid #0066cc;
	padding:0px;
	background-color:#ebf7fe;
}
.calendar_arrow_right:hover
{
	border:1px solid #0066cc;
	padding:0px;
	background-color:#ebf7fe;
}

.calendar_title
{
	position:absolute;
	bottom:7px;
	right:20px;
	left:20px;
	text-align:center;
	cursor:pointer;
}
</style>
<script>
var calendar_id = 0
function Calendar()
{
	this.mode = 0
	this.id = (calendar_id++);
	this.firstDayOfWeek = 0;
	this.selectedDate = new Date();
	this.displayedDate = new Date();

	this.onSelect = null
}

var CalendarDays = new Array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
var CalendarDaysShort = new Array('Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa');
var CalendarMonths = new Array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
var CalendarMonthsShort = new Array('Jan', 'Fév', 'Mars', 'Avr', 'Mai', 'Juin', 'Juil', 'Août', 'Sept', 'Oct', 'Nov', 'Déc');

Calendar.prototype.display = function(container)
{
	var ch = '<div id="calendar_box_'+this.id+'" class="calendar_box"> \
	<div class="calendar_head"> \
		<div class="calendar_arrow_left" id="calendar_arrow_left_'+this.id+'">&nbsp;</div> \
		<div class="calendar_title" id="calendar_title_'+this.id+'">title</div> \
		<div class="calendar_arrow_right" id="calendar_arrow_right_'+this.id+'">&nbsp;</div> \
	</div> \
	<div class="calendar_body"> \
		<table id="calendar_mode_0_'+this.id+'" border=0 class="calendar_mode calendar_mode_0" cellpadding=0 cellspacing=0> \
			<tr class="calendar_mode_0_head">';
	for(var d=0; d<7; d++)
	{
		ch+='<td>'+CalendarDaysShort[(this.firstDayOfWeek+d)%7]+'</td>';
	}
	ch+='</tr>';
	for(var w=0; w<6; w++)
	{
		ch+='<tr>';
		for(var d=0; d<7; d++)
		{
			ch+='<td class="calendar_in"></td>';
		}
		ch+='</tr>';
	}
	ch+='</table> \
		<table id="calendar_mode_1_'+this.id+'" border=0 class="calendar_mode calendar_mode_1" cellpadding=0 cellspacing=0>';

	for(var i=0; i<3; i++)
	{
		ch+='<tr>';
		for(var j=0; j<4; j++)
		{
			ch+='<td month="'+(i*4+j)+'">'+CalendarMonthsShort[i*4+j]+'</td>';
		}
		ch+='</tr>';
	}
	ch+='</table> \
		<table id="calendar_mode_2_'+this.id+'" border=0 class="calendar_mode calendar_mode_2" cellpadding=0 cellspacing=0>';

	for(var i=0; i<5; i++)
	{
		ch+='<tr>';
		for(var j=0; j<2; j++)
		{
			ch+='<td></td>';
		}
		ch+='</tr>';
	}
	ch+='</table> \
		<table id="calendar_mode_3_'+this.id+'" border=0 class="calendar_mode calendar_mode_2" cellpadding=0 cellspacing=0>';

	for(var i=0; i<5; i++)
	{
		ch+='<tr>';
		for(var j=0; j<2; j++)
		{
			ch+='<td></td>';
		}
		ch+='</tr>';
	}
	ch+='</table> \
	</div> \
	<div class="calendar_foot" id="calendar_foot_'+this.id+'"></div> \
</div>'
	container.innerHTML = ch
	this.refresh();
	this.refreshFooter();

	var thisObject = this;

	document.getElementById('calendar_arrow_left_'+this.id).onclick = function()
	{
		thisObject.moveBack()
	}
	document.getElementById('calendar_arrow_right_'+this.id).onclick = function()
	{
		thisObject.moveNext()
	}
	document.onkeyup = function(e)
	{
		if(window.event)
		{
			var code = window.event.keyCode
			var jump = window.event.ctrlKey || window.event.shiftKey
		}
		else
		{
			var code = e.keyCode
			var jump = e.ctrlKey || e.shiftKey
		}
		switch(code)
		{
			case 37:
				
				switch(thisObject.mode)
				{
					case 0:
						if(jump)
						{
							thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()-1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setDate(thisObject.selectedDate.getDate()-1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 1:
						if(jump)
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()-1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()-1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 2:
						if(jump)
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()-10);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()-1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 3:
						thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()-10);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
				}
				break;
			case 38:
				switch(thisObject.mode)
				{
					case 0:
						if(jump)
						{
							thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()-1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setDate(thisObject.selectedDate.getDate()-7);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 1:
						if(jump)
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()-1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()-4);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 2:
						if(jump)
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()-10);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()-2);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 3:
						thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()-20);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
				}
				break;
			case 39:
				switch(thisObject.mode)
				{
					case 0:
						if(jump)
						{
							thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()+1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setDate(thisObject.selectedDate.getDate()+1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 1:
						if(jump)
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()+1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()+1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 2:
						if(jump)
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()+10);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()+1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 3:
						thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()+10);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
				}
				break;
			case 40:
				switch(thisObject.mode)
				{
					case 0:
						if(jump)
						{
							thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()+1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setDate(thisObject.selectedDate.getDate()+7);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 1:
						if(jump)
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()+1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()+4);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 2:
						if(jump)
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()+10);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						else
						{
							thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()+2);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						}
						break;
					case 3:
						thisObject.selectedDate.setFullYear(thisObject.selectedDate.getFullYear()+20);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
				}
				break;
			case 36:
				switch(thisObject.mode)
				{
					case 0:
						thisObject.selectedDate.setDate(1);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
					case 1:
						thisObject.selectedDate.setMonth(0);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
					case 2:
						thisObject.selectedDate.setFullYear(Math.floor(thisObject.selectedDate.getFullYear()/10)*10);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
					case 3:
						thisObject.selectedDate.setFullYear(Math.round(thisObject.selectedDate.getFullYear()/100)*100-50);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
				}
				break;
			case 35:
				switch(thisObject.mode)
				{
					case 0:
						thisObject.selectedDate.setDate(thisObject.selectedDate.lastDayOfMonth());thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
					case 1:
						thisObject.selectedDate.setMonth(11);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
					case 2:
						thisObject.selectedDate.setFullYear(Math.floor(thisObject.selectedDate.getFullYear()/10)*10+9);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
					case 3:
						thisObject.selectedDate.setFullYear(Math.round(thisObject.selectedDate.getFullYear()/100)*100+49);thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());thisObject.refresh();thisObject.refreshFooter();
						break;
				}
				break;
			case 34:
				if(thisObject.mode>0)
				{
					thisObject.mode--;
					thisObject.refresh();
				}
				break;
			case 13:
				if(thisObject.mode>0)
				{
					thisObject.mode--;
					thisObject.refresh();
				}
				else
				{
					thisObject._onSelect()
				}
				break;
			case 33:
				if(thisObject.mode<3)
				{
					thisObject.mode++;
					thisObject.refresh();
				}
				break;
			default:
				//alert(code);
			
		}
	}
	document.onkeypress = function(e)
	{
		if(window.event)
		{
			var code = window.event.keyCode
			var jump = window.event.ctrlKey || window.event.shiftKey
		}
		else
		{
			var code = e.keyCode
			var jump = e.ctrlKey || e.shiftKey
		}
		switch(code)
		{
			case 13:
				if(thisObject.mode==0)
				{
					thisObject._onSelect()
				}
				break;			
		}
	}

	if (window.HTMLElement)
	{
		document.getElementById("calendar_box_"+this.id).addEventListener('DOMMouseScroll', function(e)
		{
			if((e.detail/3)<0)
			{
				thisObject.moveBack()
			}
			else
			{
				thisObject.moveNext()
			}
		}, false);
	}
	else
	{
		document.getElementById("calendar_box_"+this.id).onmousewheel = function()
		{
			if(window.opera)
			{
				if((event.wheelDelta/120)<0)
				{
					thisObject.moveBack()
				}
				else
				{
					thisObject.moveNext()
				}
			}
			else
			{
				if((-event.wheelDelta/120)<0)
				{
					thisObject.moveBack()
				}
				else
				{
					thisObject.moveNext()
				}
			}
		}
	}

	document.getElementById('calendar_mode_0_'+this.id).onclick = function(e)
	{
		if(window.event)
		{
			var target = window.event.srcElement
		}
		else
		{
			var target = e.target
		}
		if(target != null && target.tagName == 'TD' && target.getAttribute('delta_month')!=null && target.getAttribute('date')!=null)
		{
			thisObject.selectedDate.setTime(thisObject.displayedDate.getTime())
			thisObject.selectedDate.setMonth(thisObject.selectedDate.getMonth()+parseInt(target.getAttribute('delta_month')))
			thisObject.selectedDate.setDate(target.getAttribute('date'))

			thisObject.refreshFooter()
			document.getElementById('calendar_foot_'+thisObject.id).onclick()
			thisObject._onSelect()
		}
	}
	document.getElementById('calendar_mode_1_'+this.id).onclick = function(e)
	{
		if(window.event)
		{
			var target = window.event.srcElement
		}
		else
		{
			var target = e.target
		}
		if(target != null && target.tagName == 'TD' && target.getAttribute('month')!=null)
		{
			thisObject.displayedDate.setMonth(target.getAttribute('month'))
			thisObject.mode = 0;
			thisObject.refresh()
		}
	}
	document.getElementById('calendar_mode_2_'+this.id).onclick = function(e)
	{
		if(window.event)
		{
			var target = window.event.srcElement
		}
		else
		{
			var target = e.target
		}
		if(target != null && target.tagName == 'TD' && target.getAttribute('year')!=null)
		{
			thisObject.displayedDate.setFullYear(target.getAttribute('year'))
			thisObject.mode = 1;
			thisObject.refresh()
		}
	}
	document.getElementById('calendar_mode_3_'+this.id).onclick = function(e)
	{
		if(window.event)
		{
			var target = window.event.srcElement
		}
		else
		{
			var target = e.target
		}
		if(target != null && target.tagName == 'TD' && target.getAttribute('year')!=null)
		{
			if(thisObject.displayedDate.getFullYear()<parseInt(target.getAttribute('year')) || thisObject.displayedDate.getFullYear()>parseInt(target.getAttribute('year'))+9)
			{
				thisObject.displayedDate.setFullYear(target.getAttribute('year'))
			}
			thisObject.mode = 2;
			thisObject.refresh()
		}
	}
	document.getElementById('calendar_title_'+this.id).onclick = function()
	{
		if(thisObject.mode<3)
		{
			thisObject.mode++;
			thisObject.refresh();
		}
	}
	document.getElementById('calendar_foot_'+this.id).onclick = function()
	{
		thisObject.displayedDate.setTime(thisObject.selectedDate.getTime());
		thisObject.mode=0;
		thisObject.refresh();
	}
}

Calendar.prototype._onSelect = function()
{
	if(this.onSelect!=null)
	{
		this.onSelect(this.selectedDate)
	}
}
Calendar.prototype.refreshFooter = function()
{
	document.getElementById('calendar_foot_'+this.id).innerHTML = CalendarDays[this.selectedDate.getDay()]+' '+this.selectedDate.getDate()+' '+CalendarMonths[this.selectedDate.getMonth()]+' '+this.selectedDate.getFullYear()

}
Calendar.prototype.refresh = function()
{
	switch(this.mode)
	{
		case 0:
			document.getElementById("calendar_mode_0_"+this.id).style.display = ''
			document.getElementById("calendar_mode_1_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_2_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_3_"+this.id).style.display = 'none'
			this.redrawDays()
			break;
		case 1:
			document.getElementById("calendar_mode_0_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_1_"+this.id).style.display = ''
			document.getElementById("calendar_mode_2_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_3_"+this.id).style.display = 'none'
			this.redrawMonths()
			break;
		case 2:
			document.getElementById("calendar_mode_0_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_1_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_2_"+this.id).style.display = ''
			document.getElementById("calendar_mode_3_"+this.id).style.display = 'none'
			this.redrawYears()
			break;
		case 3:
			document.getElementById("calendar_mode_0_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_1_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_2_"+this.id).style.display = 'none'
			document.getElementById("calendar_mode_3_"+this.id).style.display = ''
			this.redrawDecades()
			break;
	}
	document.getElementById("calendar_box_"+this.id).className+=""
}
Calendar.prototype.redrawDays = function()
{
	var date = new Date();
	date.setTime(this.displayedDate.getTime());

	document.getElementById("calendar_title_"+this.id).innerHTML = CalendarMonths[date.getMonth()]+", "+date.getFullYear();

	date.setDate(1);

	var back = 0-((date.getDay()-this.firstDayOfWeek)+7)%7
	var limite = date.lastDayOfMonth();

	var t_sel = new Date()
	t_sel.setTime(this.selectedDate.getTime())
	t_sel.setHours(0)
	t_sel.setMinutes(0)
	t_sel.setSeconds(0)
	t_sel.setSeconds(0)
	t_sel.setMilliseconds(0)
	var t_dis = new Date()
	t_dis.setTime(date.getTime())
	t_dis.setHours(0)
	t_dis.setMinutes(0)
	t_dis.setSeconds(0)
	t_dis.setMilliseconds(0)
	var d_diff = Math.round((t_sel.getTime() - t_dis.getTime()) / (24*60*60*1000)) - back
	
	if(back==0)
	{
		var counter = 1;
		var area = 1;
	}
	else
	{
		date.setMonth(date.getMonth()-1)
		var counter = date.lastDayOfMonth() + back + 1;
		var area = 0
	}
	var t = document.getElementById('calendar_mode_0_'+this.id)
	
	if(t.getAttribute("last_sel")!=null)
	{
		var s = t.getAttribute("last_sel").split(',');
		t.rows[parseInt(s[0])+1].cells[parseInt(s[1])].removeAttribute("selected")
	}
	if(d_diff>=0 && d_diff<=35)
	{
		var s = new Array(Math.floor(d_diff/7), d_diff%7);
		t.rows[s[0]+1].cells[s[1]].setAttribute("selected", 1)
		t.setAttribute("last_sel", s.join(','));
	}
	else
	{
		t.removeAttribute("last_sel");
	}

	if(t.getAttribute("last_draw_month") != null)
	{
		if(t.getAttribute("last_draw_month") == date.getMonth() && t.getAttribute("last_draw_year") == date.getFullYear())
		{
			return
		}
	}
	t.setAttribute("last_draw_month", date.getMonth());
	t.setAttribute("last_draw_year", date.getFullYear());

	for(var w=0; w<6; w++)
	{
		var r = t.rows[w+1];
		for(var d=0; d<7; d++)
		{
			r.cells[d].innerHTML = counter;
			r.cells[d].setAttribute('delta_month', -1+area);
			r.cells[d].setAttribute('date', counter);
			if(w==0 || w>3)
			{
				r.cells[d].className = (area!=1?"calendar_out":"calendar_in")
			}
			d_diff--
			counter++
			back++;
			if(back == 0 || back == limite)
			{
				counter = 1
				area++;
			}
		}
	}

}
Calendar.prototype.redrawMonths = function()
{
	var date = new Date();
	date.setTime(this.displayedDate.getTime());

	document.getElementById("calendar_title_"+this.id).innerHTML = date.getFullYear();

	if(date.getFullYear() == this.selectedDate.getFullYear())
	{
		var now = this.selectedDate.getMonth();
	}
	else
	{
		var now = -1
	}

	var t =document.getElementById('calendar_mode_1_'+this.id)

	if(t.getAttribute("last_sel")!=null)
	{
		var s = t.getAttribute("last_sel").split(',');
		t.rows[parseInt(s[0])].cells[parseInt(s[1])].removeAttribute("selected")
	}
	if(this.selectedDate.getFullYear() == date.getFullYear())
	{
		var s = new Array(Math.floor(this.selectedDate.getMonth()/4), this.selectedDate.getMonth()%4);
		t.rows[s[0]].cells[s[1]].setAttribute("selected", 1)
		t.setAttribute("last_sel", s.join(','));
	}
	else
	{
		t.removeAttribute("last_sel");
	}
}
Calendar.prototype.redrawYears = function()
{
	var date = new Date();
	date.setTime(this.displayedDate.getTime());
	var d1 = Math.floor(date.getFullYear()/10)*10

	document.getElementById("calendar_title_"+this.id).innerHTML = d1+" - "+(d1+9);

	var now = this.selectedDate.getFullYear();

	var t =document.getElementById('calendar_mode_2_'+this.id)
	
	if(t.getAttribute("last_sel")!=null)
	{
		var s = t.getAttribute("last_sel").split(',');
		t.rows[parseInt(s[0])].cells[parseInt(s[1])].removeAttribute("selected")
	}
	if(this.selectedDate.getFullYear() >= d1 && this.selectedDate.getFullYear() <= d1+9)
	{
		var s = new Array(Math.floor((this.selectedDate.getFullYear() - d1)/2), (this.selectedDate.getFullYear() - d1)%2);
		t.rows[s[0]].cells[s[1]].setAttribute("selected", 1)
		t.setAttribute("last_sel", s.join(','));
	}
	else
	{
		t.removeAttribute("last_sel");
	}
	if(t.getAttribute("last_draw_year") != null)
	{
		if(t.getAttribute("last_draw_year") == Math.floor(date.getFullYear()/10)*10)
		{
			return
		}
	}
	t.setAttribute("last_draw_year", Math.floor(date.getFullYear()/10)*10);

	for(var i=0; i<5; i++)
	{
		var r = t.rows[i];
		for(var j=0; j<2; j++)
		{
			r.cells[j].innerHTML = d1;
			r.cells[j].setAttribute('year', d1);
			d1++;
		}
	}

}

Calendar.prototype.redrawDecades = function()
{
	var date = new Date();
	date.setTime(this.displayedDate.getTime());
	var d1 = Math.round(date.getFullYear()/100)*100 -50

	document.getElementById("calendar_title_"+this.id).innerHTML = d1+" - "+(d1+99);

	var t =document.getElementById('calendar_mode_3_'+this.id)
	
	if(t.getAttribute("last_sel")!=null)
	{
		var s = t.getAttribute("last_sel").split(',');
		t.rows[parseInt(s[0])].cells[parseInt(s[1])].removeAttribute("selected")
	}
	if(this.selectedDate.getFullYear() >= d1 && this.selectedDate.getFullYear() <= d1+99)
	{
		var s = new Array(Math.floor(((Math.floor(this.selectedDate.getFullYear()/10)*10) - d1)/20), (((Math.floor(this.selectedDate.getFullYear()/10)*10) - d1)/10)%2);
		t.rows[s[0]].cells[s[1]].setAttribute("selected", 1)
		t.setAttribute("last_sel", s.join(','));
	}
	else
	{
		t.removeAttribute("last_sel");
	}
	if(t.getAttribute("last_draw_year") != null)
	{
		if(t.getAttribute("last_draw_year") == Math.round(date.getFullYear()/100)*100 -50)
		{
			return
		}
	}
	t.setAttribute("last_draw_year", Math.round(date.getFullYear()/100)*100 -50);

	for(var i=0; i<5; i++)
	{
		var r = t.rows[i];
		for(var j=0; j<2; j++)
		{
			r.cells[j].innerHTML = d1+" - "+(d1+9);
			r.cells[j].setAttribute('year', d1);
			d1+=10;
		}
	}

}
Calendar.prototype.moveBack = function(jump)
{
	if(jump==null) jump = false;
	switch(this.mode)
	{
		case 0:
			if(jump)
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()-1)
			}
			else
			{
				this.displayedDate.setMonth(this.displayedDate.getMonth()-1)
			}
			this.redrawDays()
			break;
		case 1:
			if(jump)
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()-10)
			}
			else
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()-1)
			}
			this.redrawMonths()
			break;
		case 2:
			if(jump)
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()-100)
			}
			else
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()-10)
			}
			this.redrawYears()
			break;
		case 3:
			this.displayedDate.setFullYear(this.displayedDate.getFullYear()-100)
			this.redrawDecades()
			break;
	}
	document.getElementById("calendar_box_"+this.id).className+=""
}
Calendar.prototype.moveNext = function(jump)
{
	if(jump==null) jump = false;
	switch(this.mode)
	{
		case 0:
			if(jump)
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()+1)
			}
			else
			{
				this.displayedDate.setMonth(this.displayedDate.getMonth()+1)
			}
			this.redrawDays()
			break;
		case 1:
			if(jump)
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()+10)
			}
			else
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()+1)
			}
			this.redrawMonths()
			break;
		case 2:
			if(jump)
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()+100)
			}
			else
			{
				this.displayedDate.setFullYear(this.displayedDate.getFullYear()+10)
			}
			this.redrawYears()
			break;
		case 3:
			this.displayedDate.setFullYear(this.displayedDate.getFullYear()+100)
			this.redrawDecades()
			break;
	}
	document.getElementById("calendar_box_"+this.id).className+=""
}
Calendar.prototype.moveFirst = function()
{
	switch(this.mode)
	{
		case 0:
			this.displayedDate.setMonth(0)
			this.redrawDays()
			break;
		case 1:
			this.displayedDate.setFullYear(Math.floor(this.displayedDate.getFullYear()/10)*10)
			this.redrawMonths()
			break;
		case 2:
			this.displayedDate.setFullYear(Math.round(this.displayedDate.getFullYear()/100)*100-50)
			this.redrawYears()
			break;
		case 3:
			this.displayedDate.setFullYear(this.displayedDate.getFullYear()-1000)
			this.redrawDecades()
			break;
	}
	document.getElementById("calendar_box_"+this.id).className+=""
}
Calendar.prototype.moveLast = function()
{
	switch(this.mode)
	{
		case 0:
			this.displayedDate.setMonth(11)
			this.redrawDays()
			break;
		case 1:
			this.displayedDate.setFullYear(Math.floor(this.displayedDate.getFullYear()/10)*10+9)
			this.redrawMonths()
			break;
		case 2:
			this.displayedDate.setFullYear(Math.round(this.displayedDate.getFullYear()/100)*100+49)
			this.redrawYears()
			break;
		case 3:
			this.displayedDate.setFullYear(this.displayedDate.getFullYear()+1000)
			this.redrawDecades()
			break;
	}
	document.getElementById("calendar_box_"+this.id).className+=""
}

Calendar.prototype.setDate = function(date)
{
	this.date = date
	this.refresh()
}

Date.prototype.lastDayOfMonth = function()
{
	switch(this.getMonth())
	{
		case 1:
			var y = this.getFullYear();
			if(y%4==0 && (y%100 != 0 || y%400==0))
				return 29
			return 28
		case 3:
		case 5:
		case 8:
		case 10:
			return 30;
		default:
			return 31;
	}
}

if (window.HTMLElement)
{

    var element = HTMLElement.prototype;

    var captureMouse = ["click", "mousedown", "mouseup", "mousemove", "mouseover", "mouseout"];
    var captureKey = ["keydown", "keyup", "keypress"];

    element.setCapture = function()
    {
        var self = this;
        var flag_mouse = false;
        var flag_key = false;
        this._captureMouse = function(e)
        {
        	
            if (flag_mouse) {return}
            flag_mouse = true;
            var event = document.createEvent("MouseEvents");
            event.initMouseEvent(e.type,
                e.bubbles, e.cancelable, e.view, e.detail,
                e.screenX, e.screenY, e.clientX, e.clientY,
                e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
                e.button, e.relatedTarget);
            self.dispatchEvent(event);
            flag_mouse = false;
        };
        this._captureKey = function(e)
        {
        	if (flag_key) {return}
        	flag_key = true;
        	var event = document.createEvent("KeyEvents");
        	event.initKeyEvent(e.type,
        		e.bubbles, e.cancelable, e.view, 
        		e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
        		e.keyCode, e.charCode);
        	self.dispatchEvent(event);
        	flag_key = false;
        };
        for (var i=0; i<captureMouse.length; i++)
        {
            window.addEventListener(captureMouse[i], this._captureMouse, true);
        }
        for (var i=0; i<captureKey.length; i++)
        {
            window.addEventListener(captureKey[i], this._captureKey, true);
        }
    };

    element.releaseCapture = function()
    {
        for (var i=0; i<captureMouse.length; i++)
        {
            window.removeEventListener(captureMouse[i], this._captureMouse, true);
        }
        for (var i=0; i<captureKey.length; i++)
        {
            window.removeEventListener(captureKey[i], this._captureKey, true);
        }
        this._captureMouse = null;
        this._captureKey = null;
    };

}

 

</script>
	</head>
	<body>
		<div id="main">
		</div>
<script type="text/javascript">
var c = new Calendar();
c.onSelect = function(d) {alert(d)}
c.display(document.getElementById('main'))
//c.setDate(new Date())
</script>
	</body>
</html>